<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=.0">
  <title>演示vue3-computed</title>
  <script src="../vue-3.0.11.js"></script>
  <style>
    a, h1{
      display: block;
    }
    #app{
      display: flex;
      flex-direction: column;
    }
    .container{
      margin: 20px;
      border: #eeeeee solid px;
    }
  </style>
</head>

<body>
  <div id="app">
    <div class="container">
      <h1>computed</h1>
      <input v-model="firstName">
      <input v-model="lastName">
      <div>{{fullName}}</div>
      <div>{{getFullName()}}</div>
      <div>{{fullName2}}</div>
    </div>

    
  </div>
  <script>
    const { createApp, ref, computed } = Vue
    const firstName = ref('a')
    const lastName = ref('')
    const fullName = computed(()=> firstName.value + lastName.value)
    function getFullName() {
      return firstName.value + lastName.value
    }

    const fullName2 = computed({
      get: () => firstName.value + lastName.value,
      set: (val) => {
        firstName.value =  val
      }
    })

    console.log(firstName.value);
    const app = {
      setup() {
        return {
          firstName,
          lastName,
          fullName,
          getFullName,
          fullName2
        }
      }
    }

    createApp(app).mount('#app')
  </script>
</body>

</html>